package com.tanhua.server.service;

import com.tanhua.dubbo.api.FreezeApi;
import com.tanhua.dubbo.api.UserInfoApi;
import com.tanhua.model.db.Freeze;
import com.tanhua.model.db.UserInfo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//自动解冻
@Component
public class Unfreeze {
    @DubboReference
    private FreezeApi freezeApi;
    @DubboReference
    private UserInfoApi userInfoApi;
    public void Unfreezes(Freeze freeze) throws ParseException {
        String untieTime = freeze.getUntieTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1 = sdf.parse(untieTime);
        //Date date1 = sdf.parse(untieTime);

            long time1 = date1.getTime();
            Date date = new Date();
            long time2= date.getTime();


            if (time2>time1){
                UserInfo user = userInfoApi.findUser(freeze.getUserId());
                user.setUserStatus("1");
                userInfoApi.update(user);
                freezeApi.deleteUser(freeze.getUserId());
                return;
            }




    }
}
